package task;


import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * header头
 *
 * @author Gyg
 * @date 2022/1/20 11:29
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class HeaderContextHolder {

    private static final InheritableThreadLocal<Map<String, String>> CONTEXT = new InheritableThreadLocal<>();

    public static void setContext(Map<String, String> map) {
        CONTEXT.set(map);
    }

    public static void removeContext() {
        CONTEXT.remove();
    }

    public static Map<String, String> getHeaders() {
        return CONTEXT.get();
    }

    public static String getHeader(String key) {
        if (isEmpty()) {
            return null;
        }
        return CONTEXT.get().get(key);
    }

    public static boolean isEmpty() {
//        return MapUtils.isEmpty(CONTEXT.get());
        return true;
    }
}
